package com.ssm.comm.session;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.Objects;

public class MyHttpServletRequestWrapper extends HttpServletRequestWrapper {

    private HttpSession session ;

    private HttpServletRequest request;
    private HttpServletResponse response;
    private String sid;

     public MyHttpServletRequestWrapper(String sid , HttpServletRequest request , HttpServletResponse response){
        super(request);
        this.sid = sid ;
        this.request = request;
        this.response= response ;
        this.session =  new MyHttpSessionWrapper(sid ,request.getSession() ,request,response);
     }
    @Override
     public HttpSession getSession(boolean create){
        if(create){
            this.request.getSession(true);
            this.sid = this.request.getSession().getId() ;
            session = new MyHttpSessionWrapper(sid ,request.getSession() ,request,response);
        }
        return this.session;
     }

     @Override
     public HttpSession getSession(){
         if(Objects.isNull(this.session)){
             this.session =  new MyHttpSessionWrapper(sid ,request.getSession() ,request,response);
         }
         return this.session ;
     }



}
